$(function () {
    let markId = getUrlString('markid');
    //调往搜索
    $('.searchDiv').click(function () {
        window.location.href = 'dancool://fullweb='+urlView+'productData/dataSearch.html?type=0';
    });
    //左侧分类列表
    function getList (){
        let data = {
            'markid':markId
        };
        getData('post','/niu/apiv4/niu_category.php',data,function (data) {
            console.log(data);
            let append = '';
            $(data.info).each(function () {
                append += '<li>' +
                    ' <input type="hidden" value="'+this.type+'"> ' +
                    ' <span>'+this.name+'</span> </li>'
            });
            $("#categoryList").append(append);
            $("#categoryList li").eq(0).addClass('active');
            $('#categoryList li').click(function () {
                let index = $(this).index();
                // let height = .height();
                let height = 0;
                for (var i = 0;i < index;i++){
                    height += $('#rightList li').eq(i).height()
                }
                // console.log(height);
                $('#rightList').animate({
                        scrollTop: height
                    }, 500
                );
            });

            $(".right").scroll(function () {
                let scrollTop = $(this).scrollTop();
                // console.log(scrollTop);
                let rightHetght = $('.right li').height();
                // console.log(rightHetght);
                let index = Math.floor(scrollTop / rightHetght);
                $('.left li').removeClass('active').eq(index).addClass('active');
            });
        });
    }

    getList();

    //右侧分类列表
    function getRightList (){
        let data = {
            'markid':markId
        };
        getData('post','/niu/apiv4/niu_category_show.php',data,function (data) {
            console.log(data);
            let append = '';
            $.each(data.info,function (key,val) {
                append += '<li><div class="title">' +
                    '                <span>'+key+'</span>' +
                    '                <img class="more" src="../../res/img/common/more.png" alt="">' +
                    '            </div>' +
                    '            <div class="imgList">' ;
                    $(val).each(function () {
                        append+= ' <input type="hidden" value="'+this.id+'"> ' +
                            '               <img class="imgid" data-id="'+this.id+'" src="'+this.pics+'" alt="">' ;
                    });
                    append += '            </div></li>'
            });
            $("#rightList").append(append);
            $("#rightList li .imgid").click(function () {
                let id = $(this).attr('data-id');
                window.location.href = 'dancool://web='+urlView+'productData/dataDetail.html?id='+id;
            });

            $('#rightList li .more').click(function () {
                let typeHtml = $(this).prev('span').html();
                $('#categoryList li').each(function () {
                    if (typeHtml === $(this).find('span').html()) {
                        let type = $(this).find('input').val();
                        console.log(type);
                        if (type === '99' || type === '100'){
                            window.location.href = 'dancool://web='+urlView+'productData/brandData.html?type='+type;
                        }else {
                            window.location.href = 'dancool://web='+urlView+'productData/dataType.html?type='+type;
                        }
                    }
                });
            })
        });
    }

    getRightList();

    $('#addIcon').click(function () {
        window.location.href = 'dancool://web='+urlView+'productData/addData.html?type=1';
    })

});